﻿using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;

public class EditorConfig
{
    public static string BundleVersion = "1.0.0";   // 程序版本号
    public static string BuildNumber = "1.0.0";     // 编译版本号(iOS),每次累加
    public static int BundleVersionCode = 1;        // 编译版本号(Android),每次累加

    // 导出类型
    public enum ExportType
    {
        ASSET_BUNDLE = 1 << 0,  // AssetBundle
        PROJECT = 1 << 1,       // 工程
    }

    public static string UpdateVersionName
    {
        get
        {
            string[] versions = Version.Split('.');
            return string.Format("{0}_release_{1}{2}", Config.UpdatePlatformName, versions[0], versions[1]);
        }
    }

    // 版本文件夹 如:/Users/Jeffy/Documents/work/3DSultans/version/[UpdateName]/[PlatformName]_release_[Version_1][Version_2]
    public static string VERSION_PATH
    {
        get
        {
            return string.Format("{0}/../version/{1}/{2}", Application.dataPath, ConfigHelper.UpdateName, EditorConfig.UpdateVersionName);
        }
    }

    public static bool COMPRESS_THREAD = true;
    // Lua包编码类型
    public static LuaData.EncodeType LUA_PACKAGE_ENCODE = LuaData.EncodeType.Normal;
    public static string TEMP_PATH = "Temp";
    // Lua编译中间文件夹
    public static string TEMP_LUA_PATH = "Temp/lua";
    public static string TEMP_LUA_PATCH_PATH = "Temp/lua_patch";
    // AssetBundle仓库
    public static string AB_STORE_PATH = "Temp/data";

    public static string SOUND_PATH = Config.DATA_ASSETS_PATH + "/sound";

    public static BuildTarget BUILD_TARGET
    {
        get
        {
#if UNITY_IOS
            return BuildTarget.iOS;
#elif UNITY_ANDROID
            return BuildTarget.Android;
#elif UNITY_STANDALONE_OSX
            return BuildTarget.StandaloneOSXIntel;
#else
            return BuildTarget.StandaloneWindows;
#endif
        }
    }

    public static string Version
    {
        get
        {
            return ConfigHelper.Version;
        }

        set
        {
            ConfigHelper.Version = value;
        }
    }

    // 音效
    static string[] sounds;
    static int[] soundIndexs;

    public static void RebuildSound()
    {
        List<string> files = FileHelper.GetAllChildFiles(SOUND_PATH, Config.SOUND_SUFFIX);
        sounds = new string[files.Count + 1];
        soundIndexs = new int[files.Count + 1];

        sounds[0] = "--";
        soundIndexs[0] = 0;
        for (int i = 0; i < files.Count; ++i)
        {
            string filename = files[i];
            sounds[i + 1] = filename.Replace(SOUND_PATH, "").Replace(string.Format(".{0}", Config.SOUND_SUFFIX), "").Substring(1);
            soundIndexs[i + 1] = i + 1;

            Debug.Log(sounds[i + 1]);
        }
    }

    public static string[] Sounds
    {
        get
        {
            if (sounds == null)
            {
                RebuildSound();
            }
            return sounds;
        }
    }

    public static int[] SoundIndexs
    {
        get
        {
            if (sounds == null)
            {
                RebuildSound();
            }
            return soundIndexs;
        }
    }

    public static string FindSound(int index)
    {
        if (index == 0)
        {
            return "";
        }
        if (index >= Sounds.Length)
        {
            index = 0;
        }
        return Sounds[index];
    }

    public static int FindSoundIndex(string name)
    {
        if (string.IsNullOrEmpty(name)) return 0;
        for (int i = 0; i < Sounds.Length; ++i)
        {
            if (string.Equals(Sounds[i], name))
            {
                return i;
            }
        }
        return -1;
    }
}